<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text"  id="d1" placeholder="请输入0-100之间的整数">
<input type="button" value="猜一猜" onclick="f()">
<div>结果：<span></span></div>
<script>
  //得到0-100随机整数
  let w = parseInt(Math.random() * 101);
  let cont=0;
  function f() {
   cont++;
      let s = document.querySelector("#d1");
      if (isNaN(s.value)) {
        console.log("输入错误")
        return;
      }
      if (s.value == w) {
        document.querySelector("span").innerText ="猜对了一共猜了"+cont+"次";
      } else if (s.value < w) {
        document.querySelector("span").innerText = "猜小了";
      } else if (s.value > w) {
        document.querySelector("span").innerText = "猜大了";
      }

  }
</script>
</body>
</html>